# 作业先完成，再完美

import requests
from threading import Thread
from multiprocessing import Process

result = []
def request_baidu(i, type):
    url = 'https://www.baidu.com/'
    body = {}
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'
    }
    response = requests.get(url=url, headers=headers)
    result.append(response)
    if type == 'process':
        print(f"{i}、result的id是{id(result)}")

if __name__ == "__main__":
    # 利用Python实现一个多线程程序
    thread_list = []
    for i in range(5):
        my_thread = Thread(target = request_baidu, args=(i, 'thread'))
        thread_list.append(my_thread)
        my_thread.start()

    for i in thread_list:
        i.join()
    # for i in result:
    print(f'线程结束:{result}')

    # 将多线程程序改为多进程程序
    process_list = []
    for i in range(5):
        my_process = Process(target = request_baidu, args=(i, 'process'))
        process_list.append(my_process)
        my_process.start()

    for i in process_list:
        i.join()
    print(f'进程结束:{result}')